#ifndef CEditDeviseH
#define CEditDeviseH
//---------------------------------------------------------------------------
#include "CtrlStd.h"
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include "CEdit.h"
#include "CComboBx.h"
#include "Eic.h"
#include "CEdit.h"
#include "CListBox.h"
#include <comctrls.hpp>
#include "CtrlStd.h"
//---------------------------------------------------------------------------
typedef int TCodeDev;
//---------------------------------------------------------------------------
#define DEVCODE(strCode, bIsEuro) ( ((bIsEuro) << 31) | *(int*)(strCode).c_str() )
#define EST_DEVISE_EURO(nCode)    ((nCode) & 0x80000000)
#define CODE_DEVISE_DEFAUT        ((TCodeDev)0)
//---------------------------------------------------------------------------
//class CDeviseString;
class PACKAGE_CTRLSTD CDevise
{
//  friend CDeviseString;
  private:
    AnsiString strCodeISO;
    AnsiString strNomDevise;
    AnsiString strNomPays;
    double     dTauxDeviseVersEuro;
    bool       bDeviseEuro;
    TCodeDev   nCode;

    void __fastcall SetTaux(double dTaux);

  public:
    __fastcall CDevise(){};
    virtual __fastcall ~CDevise(){};
    __fastcall CDevise(TCodeDev nCode, double dTaux = -1);
    __fastcall CDevise(const AnsiString &NomPays,const AnsiString &NomDevise,const AnsiString &CodeDevise,double dTaux);

    CDevise &__fastcall operator =  (const CDevise &pDevInfos);
    bool     __fastcall operator == (const CDevise &pDevInfos) const;
    bool     __fastcall operator != (const CDevise &pDevInfos) const;
    bool     __fastcall operator <  (const CDevise &pDevInfos) const;
    void     __fastcall Clear(void);
    void     __fastcall ForceTauxEuro(double dTaux);

    bool     __fastcall GetDeviseHorsZoneEuro( void) const;

    __property TCodeDev   Code            = { read=nCode                              };
    __property AnsiString CodeISO         = { read=strCodeISO                         };
    __property bool       EstDeviseEuro   = { read=bDeviseEuro                        }; // FRF, DEM, ... mais pas EUR
    __property bool       EstHorsZoneEuro = { read=GetDeviseHorsZoneEuro              }; // Tout sauf FRF, DEM, ... et EUR
    __property AnsiString Nom             = { read=strNomDevise                       };
    __property AnsiString Pays            = { read=strNomPays                         };
    __property double     Taux            = { read=dTauxDeviseVersEuro, write=SetTaux };
};
//---------------------------------------------------------------------------
/*class CDeviseString : public CDevise
{
   public:
    __fastcall CDeviseString(const AnsiString &strDevisesInfos);
    virtual __fastcall ~CDeviseString(){};
};*/
//---------------------------------------------------------------------------
class PACKAGE_CTRLSTD CEditDevise : public CCustomEdit
{
  typedef void __fastcall ( __closure *TDeviseChangeEvent)( TObject* Sender, bool bDeviseValide);

  private:
    TBitBtn      *m_psbListe;
    TBitBtn      *m_psbTaux;
    CEdit        *m_pedTaux;
    TForm        *m_pfrmListe;
    TLabel       *m_pLabel;
    int           m_nWidth;
    AnsiString    m_strSaveCodeISO;
    bool          m_bEnabled;
    int           m_nSizeEsp;
    bool          m_bReadOnly;
    bool          m_bShowEditTaux;
    bool          m_bTabStop;
    bool          m_bVisible;
    CDevise       m_devInfos;
    bool          m_bKillFocus;
    bool          m_bDefValue;
    bool          m_bInitSort;
    TNotifyEvent  m_pOnExit;
    TNotifyEvent  m_pOnExitTaux;
    TListView    *m_plvDevise;
    TListColumn  *m_pColumnSort;

    TDeviseChangeEvent m_pDeviseChangeEvent;

    void __fastcall sbListeClick( TObject *pSender);
    void __fastcall frmListeOnDeactivate( TObject *pSender);
    void __fastcall lvDeviseOnKeyDown( TObject* pSender, Word &Key, TShiftState Shift);
    void __fastcall edOnChange( TObject *pSender);
    void __fastcall edTauxOnIllegalChar(CCustomEdit *pedSender, WORD &cIllegalCharCode, bool &bAccept);
    void __fastcall edOnExit( TObject *pSender);
    void __fastcall edTauxOnExit( TObject *pSender);
    void __fastcall edTauxOnChange( TObject *pSender);
    void __fastcall ColumnClick( TObject *pSender, TListColumn *pColumn);
    void __fastcall lvDeviseOnClick( TObject *pSender);
    void __fastcall edTauxOnDblClick( TObject *pSender);
    void __fastcall edTauxOnEnter( TObject *pSender);
    void __fastcall sbTauxClick( TObject *pSender);
    void __fastcall sbTauxOnEnter( TObject *pSender);

    AnsiString __fastcall GetLibelle( void) const;
    TFont *__fastcall GetLibelleFont( void) const;
    AnsiString __fastcall GetText( void) /*const*/;
    CDevise __fastcall GetDeviseInfos( void) const;
    AnsiString __fastcall GetCodeISO( void) /*const*/;
    TCodeDev   __fastcall GetCodeDevise(void) const;
    double __fastcall GetTauxChange( void) const;
    bool __fastcall GetReadOnly( void) const;
    bool __fastcall GetEnabled( void);

    void __fastcall SetEnabled( bool bValue);
    void __fastcall SetLibelle( const AnsiString strValue);
    void __fastcall SetLibelleFont( TFont *pFont);
    void __fastcall SetReadOnly( bool bValue);
    void __fastcall SetShowEditTaux( bool bValue);
    void __fastcall SetWidth ( int nValue);
    void __fastcall SetSizeEspace( int nValue);
    void __fastcall SetTabStop( bool bValue);
    void __fastcall SetText( const AnsiString strValue);
    void __fastcall SetVisible( bool bValue);
    void __fastcall SetCodeDevise( TCodeDev nValue);
    void __fastcall SetTauxChange( double dTaux);

    void __fastcall FORCE_SAISIE_TAUX( void);

  protected:
    virtual void __fastcall SetParent( TWinControl* pAParent);
    virtual void __fastcall WndProc( TMessage &Message);
    virtual void __fastcall Loaded(void);

  public:
    static TStringList *CM_LstDevises;
    __fastcall  CEditDevise( TComponent* Owner);
    virtual __fastcall ~CEditDevise(){};

    void __fastcall SetCodeISOFocus( void);
    void __fastcall SetTauxFocus   ( void);
    bool __fastcall TauxEstCorrectementRempli();

    __property TCodeDev   CodeDevise   = { read=GetCodeDevise  , write=SetCodeDevise                  };
    __property CDevise    DeviseInfos  = { read=GetDeviseInfos                                        };
    __property AnsiString CodeISO      = { read=GetCodeISO                                            };
    __property double     TauxChange   = { read=GetTauxChange  , write=SetTauxChange                  };

    __property TForm     *FormAssistance = { read=m_pfrmListe, write=m_pfrmListe };
    __property TListView *ListeDevises   = { read=m_plvDevise, write=m_plvDevise };


  __published:
    __property            Ctl3D;
    __property            BorderStyle;
    __property bool       DefaultValue = { read=m_bDefValue    , write=m_bDefValue    , default=true  };
    __property bool       Enabled      = { read=GetEnabled     , write=SetEnabled     , default=true  };
    __property            Font;
    __property AnsiString Libelle      = { read=GetLibelle     , write=SetLibelle                     };
    __property TFont     *LibelleFont  = { read=GetLibelleFont , write=SetLibelleFont                 };
    __property bool       ReadOnly     = { read=GetReadOnly    , write=SetReadOnly    , default=false };
    __property bool       ShowEditTaux = { read=m_bShowEditTaux, write=SetShowEditTaux, default=true  };
    __property int        SizeEspace   = { read=m_nSizeEsp     , write=SetSizeEspace  , default=10    };
    __property            TabOrder;
    __property bool       TabStop      = { read=m_bTabStop     , write=SetTabStop     , default=true  };
    __property AnsiString Text         = { read=GetText        , write=SetText                        };
    __property bool       Visible      = { read=m_bVisible     , write=SetVisible     , default=true  };
    __property int        Width        = { read=m_nWidth       , write=SetWidth       , default=100   };

    __property TDeviseChangeEvent OnChange   = { read=m_pDeviseChangeEvent, write=m_pDeviseChangeEvent  };
    __property                    OnEnter;
    __property TNotifyEvent       OnExit     = { read=m_pOnExit           , write=m_pOnExit             };
    __property TNotifyEvent       OnExitTaux = { read=m_pOnExitTaux       , write=m_pOnExitTaux         };
};
//---------------------------------------------------------------------------
// Déclaration des variables et fonction pouvant être appelé de l'extérieur
extern PACKAGE_CTRLSTD const TCodeDev DeviseCodeEuro;
extern PACKAGE_CTRLSTD const TCodeDev DeviseCodeFranc;
extern PACKAGE_CTRLSTD       TCodeDev DeviseCodeDefaut;
extern PACKAGE_CTRLSTD const CDevise &DeviseEuro;
extern PACKAGE_CTRLSTD const CDevise &DeviseFranc;
extern PACKAGE_CTRLSTD       CDevise *DeviseDefaut;
extern PACKAGE_CTRLSTD CCurrency __fastcall DeviseConvToDef   (const CDevise   &cInfosDev, const CCurrency &curMontantOrg);
extern PACKAGE_CTRLSTD CCurrency __fastcall DeviseConvTo      (const CDevise   &cInfosDev, const CCurrency &curMontantOrg, const CDevise &cInfosDevTo);
#define ConvertEuroToFranc(X) DeviseConvTo(DeviseEuro,X,DeviseFranc)
#define ConvertFrancToEuro(X) DeviseConvTo(DeviseFranc,X,DeviseEuro)
#define ConvertEntierEuroToFranc(X) lArrond(DeviseConvTo(DeviseEuro,X,DeviseFranc))
#define ConvertEntierFrancToEuro(X) lArrond(DeviseConvTo(DeviseFranc,X,DeviseEuro))
extern PACKAGE_CTRLSTD void     __fastcall DeviseChangeDefaut(const TCodeDev   nCodeDev);
extern PACKAGE_CTRLSTD bool     __fastcall DeviseEstValide   (const TDateTime &dtDateImputation, const CDevise &cInfosDev, AnsiString &strErrorMsg);
//---------------------------------------------------------------------------
extern PACKAGE_CTRLSTD void       __fastcall DeviseShowTauxEuro(void);
//extern PACKAGE_CTRLSTD void       __fastcall DeviseInitTaux    (const TStrings *pLstTaux);
//extern PACKAGE_CTRLSTD bool       __fastcall DeviseGetTaux     (      TStrings *pLstTaux);
extern PACKAGE_CTRLSTD AnsiString __fastcall DeviseGetStringDeviseTenue(const bool bIsEuro);
extern PACKAGE_CTRLSTD AnsiString __fastcall DeviseTauxToStr(double dTaux);
extern PACKAGE_CTRLSTD TCodeDev   __fastcall DeviseGetCodeDev( const AnsiString &strCodeISO);
extern PACKAGE_CTRLSTD void       __fastcall DeviseGetListCodeISO( TStrings *pListCodeDevise);
//---------------------------------------------------------------------------
extern PACKAGE_CTRLSTD AnsiString __fastcall DeviseSaisirTauxChange( int nXScreen, int nYScreen, const CDevise &eDevise);
//---------------------------------------------------------------------------
#endif
